package org.blogwu.learn.multithread.chapter3.demo20;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;

public class Main {

    static volatile AtomicInteger atomicInteger = new AtomicInteger(0);

    public static class AtomicThread extends Thread {
        @Override
        public void run() {
            for (int i = 0; i < 1000; i++) {
                atomicInteger.getAndIncrement();
            }
        }
    }

    public static void main(String[] args) throws InterruptedException {
        ExecutorService executorService = Executors.newFixedThreadPool(200);
        for (int i = 0; i < 200; i++) {
            executorService.submit(new AtomicThread());
        }
        executorService.shutdown();
        executorService.awaitTermination(1, TimeUnit.HOURS);
        System.out.println(atomicInteger.get());
    }
}
